package com.qq2008.game.mojie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qq2008.game.mojie.jdo.Role;
import com.qq2008.game.mojie.mapper.RoleMapper;
import com.qq2008.game.mojie.mapper.RolePlusMapper;
import com.qq2008.game.mojie.server.RoleServer;
import com.qq2008.game.mojie.service.RolePlusService;
import com.qq2008.game.mojie.service.impl.RolePlusServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/mojie")
public class PlayerController {


    @Autowired
    private RolePlusServiceImpl rolePlusService;

    /**
     * 获取玩家信息
     */
    @GetMapping(value = "/infoOther")
    public String infoOther(Model model, HttpSession session, Integer roleId) {
        Role role = rolePlusService.getRole(roleId);
        Role roleWhose = getSessionRole(session);
        model.addAttribute("name", role.getNickName());
        model.addAttribute("role", role);
        model.addAttribute("pageTitle", "玩家信息");
        if(roleWhose.getUserId()!=roleId){
            model.addAttribute("isShowAdd", 1);//显示加好友按钮
        }
        return "info";
    }


    private Role getSessionRole(HttpSession session) {
        return RoleServer.getRole((int) session.getAttribute("roleId"));
    }
}
